/*
 * To change this license header, choose License Headers in Project Properties.
 * To change this template file, choose Tools | Templates
 * and open the template in the editor.
 */
package student;

import common.MessageModel;
import common.Message_Type;
import java.net.InetAddress;
import java.net.Socket;
import javax.swing.JButton;
import javax.swing.JDialog;
import javax.swing.JLabel;
import javax.swing.JTextArea;

/**
 *
 * @author Eugene-Forest
 */
public class StudentThread extends Thread {

    private Socket socket;
    private int port;
    private InetAddress address;
    private JDialog noticeDialog;
    private JTextArea noticeArea;
    private JButton noticeButton;
    private JLabel publishJLabel;
    private JTextArea message_panel;

    public StudentThread(int port, InetAddress address, JDialog noticeDialog,
            JTextArea noticeArea, JButton noticeButton,JLabel publishJLabel,JTextArea message_panel) {
        this.port = port;
        this.address = address;
        this.noticeDialog = noticeDialog;
        this.noticeArea = noticeArea;
        this.noticeButton = noticeButton;
        this.publishJLabel=publishJLabel;
        this.message_panel=message_panel;
    }
    
    public Socket getSocket(){
        return socket;
    }

    @Override
    public void run() {
        try {
            //连接服务端
            socket = new Socket(address, port);
            //开启接收线程
            new ReceiveNoticeThread(socket, noticeDialog,noticeArea,noticeButton,
                    publishJLabel,message_panel).start();
            //获取教师今日发送的历史公告
            new SendThread(socket, new MessageModel(Message_Type.Review)).start();
        } catch (Exception e) {
            System.out.println("do it error");
        }
    }

}
